<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/12 0012
  Time: 12:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="common/css_js.jsp"></jsp:include>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="container mt-3">
<form  onsubmit="return false;">
    <input class="form-control" type="text" name="e_name" id="e_name" placeholder="真实姓名"><br>
    <input class="form-control" type="text" name="e_sex" id="e_sex" placeholder="请输入性别"><br>
    <input class="form-control" type="text" <%--onblur="check()"--%> name="e_username" id="e_username" placeholder="请输入账号"><br>
    <input class="form-control" type="text" name="e_password" id="e_password" placeholder="请输入密码"><br>
    <button class="btn btn-success" type="button" onclick="addOneEmployee()">提交</button>
</form>
</div>
</body>
<script src="<%=path%>/static/jquery/jquery-3.6.0.min.js"></script>
<script>
    function addOneEmployee() {
        var e_name = $("#e_name").val();
        var e_sex = $("#e_sex").val();
        var e_username = $("#e_username").val();
        var e_password = $("#e_password").val();
        //判断用户是否输入全部信息
        if((e_name != null || e_name !="") && (e_sex!=null || e_sex!="")
            && (e_username != null || e_username !="") && (e_password != null || e_password !="")){
            $.ajax({
                url:"addEmployee",
                method:"post",
                dataType: "text",
                /*contentType:"application/x-www.-form-urlencoded",*/
                data:{
                    e_name:e_name,
                    e_sex:e_sex,
                    e_username:e_username,
                    e_password:e_password,
                },
                success:function (result) {
                    if(result == "success"){
                        alert("添加成功");
                        //刷新父层
                        parent.location.reload();
                        //关闭本层
                        layer_close();
                    }else {
                        alert("添加失败");
                    }
                },error:function (e) {
                    alert("服务器错误");
                }
            })
        }else {
            alert("请输入全部信息");
        }
    }
    /*function check() {
        $.ajax({
            url:"checkAdmin",
            method:"post",
            dataType: "text",
            /!*contentType:"application/x-www.-form-urlencoded",*!/
            data:{
                a_username:$("#a_username").val()
            },
            success:function (result) {
                if(result == "success"){
                }else {
                    alert("该用户已存在");
                }
            },error:function (e) {
                alert("服务器错误");
            }
        })
    }*/
</script>
</html>
